﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Itop.GpsCar.Model;

namespace Itop.GpsCar.Web
{
    public partial class Tracking : System.Web.UI.Page
    {
        public string deviceID = "1";
        public bool DrawLine = false;
        private DateTime timeStamp;
        public class MapPoint
        {
            public MapPoint(double jd, double wd)
            {
                x = jd;
                y = wd;
            }
            public double x;
            public double y;
            public string pl = "0";
            public double speed = 0;
            public string strTime = "00:00:00";
        }
        public static IList<MapPoint> marlist = new List<MapPoint>();
        public static IList<MapPoint> pointlist = new List<MapPoint>();
        public static IList<long> posID = new List<long>();
        protected void Page_Load(object sender, EventArgs e)
        {
            marlist.Clear();
            object obj = Global.SqlMapper.GetObject("SelectdevicecarrierList", " where device_id = " + deviceID);
            System.Collections.Generic.IList<position> posList = Global.SqlMapper.GetList<position>("SelectpositionList", " where device_id = " + deviceID + " order by timestamp desc");
            if (posList.Count > 0)
            {

                MapPoint mp = new MapPoint(posList[0].latitude, posList[0].longitude);
                mp.speed = posList[0].speed;
                mp.strTime = posList[0].timestamp.ToString();
                if (obj != null)
                {
                    object car = Global.SqlMapper.GetObject("SelectcarrierList", " where idCarrier = " + (obj as devicecarrier).carrier_id);
                    if (car != null)
                    {
                        mp.pl = (car as carrier).plate;
                    }
                    else
                    {
                        mp.pl = "0";
                    }
                }
                else
                {
                    mp.pl = "0";
                }

                marlist.Add(mp);
                if (!posID.Contains(posList[0].idPosition))
                {
                    pointlist.Add(mp);
                    posID.Add(posList[0].idPosition);
                    DrawLine = true;
                }

            }
        
        }
    }
}
